/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.shuaijiang.action;

import com.shuaijiang.net.NetInterfaceInfoUtil;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.SwingWorker;

/**
 *
 * @author atom
 */
public class InterfaceScanningWorker extends SwingWorker<List<String>, Object> {

    private javax.swing.JComboBox comboBox;
    private javax.swing.JList List;
    private ComboBoxModel comboBoxMode;

    public InterfaceScanningWorker(JComboBox comboBox, JList List) {
        this.comboBox = comboBox;
        this.List = List;
        comboBoxMode=new DefaultComboBoxModel();
    }

    
    
    
    
    @Override
    protected void done() {
        try {
                comboBox.setModel(comboBoxMode);
                for(String networks:get()){
                    comboBox.addItem(networks);
                }
          comboBox.setModel(comboBoxMode);
        } catch (InterruptedException ex) {
            Logger.getLogger(InterfaceScanningWorker.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ExecutionException ex) {
            Logger.getLogger(InterfaceScanningWorker.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    protected List<String> doInBackground() throws Exception {
        List<String>networks=new ArrayList<String>();
        for(NetworkInterface face:NetInterfaceInfoUtil.getNetworkInterfaces()){
            networks.add(face.getName());
        }
        return networks;
    }

    
    
}
